import { getCategory1List, getCategory2List, getCategory3List } from "@/api/product/category";
import { defineStore } from "pinia";
import type { CategoryState } from "./interface";

export const useCategoryStore  = defineStore('useCategoryStore ', {

	state: ():CategoryState=> ({
        category1Id: undefined ,// 选择的一级id
        category2Id: undefined,// 选择的二级id
        category3Id: undefined,// 选择的三级id
        category1List:[],
        category2List:[],
        category3List:[],
        
  }),

	actions: {
    async getCategory1List(){
    this.category1List =await getCategory1List()
    },
    //  请求获取二级分类列表并更新category2List
    async getCategory2List(category1Id: number) {
        // 将传入的一级id保存到state中
        this.category1Id = category1Id
        // 请求获取二级分类列表并更新category2List
        this.category2List = await getCategory2List(category1Id)
      },
  
    //  请求获取三级分类列表并更新category3List
    async getCategory3List(category2Id: number) {
        // 将传入的二级id保存到state中
        this.category2Id = category2Id
        // 请求获取三级分类列表并更新category3List
        this.category3List = await getCategory3List(category2Id)
      } 
      },

    
})




function getCategory1ListApi() {
    throw new Error("Function not implemented.");
}

